package com.mingdong.first.guanchazhe.subject;

import java.util.ArrayList;
import java.util.List;

import com.mingdong.first.guanchazhe.interfac.Observer;
import com.mingdong.first.guanchazhe.interfac.Subject;

public class WeatherData implements Subject {

	private float mTemperate;
	private float mPressure;
	private float mHumidity;
	private List<Observer> observerList;
	
	public WeatherData(){
		observerList = new ArrayList<Observer>();
	}
	
	public void registerObserver(Observer o) {
		observerList.add(o);
	}

	public void removeObserver(Observer o) {
		if(observerList.contains(o)){
			
			observerList.remove(o);
		}
	}

	public void notifyObservers() {
		for (Observer o : observerList) {
			o.update(getmTemperate(), getmPressure(), getmHumidity());
		}
	}

	public void setData(float mTemperate, float mPressure, float mHumidity){
		this.mTemperate = mTemperate;
		this.mHumidity = mHumidity;
		this.mPressure = mPressure;
		dataChange();
	}
	
	public void dataChange(){
		notifyObservers();
	}
	
	public float getmTemperate() {
		return mTemperate;
	}

	public float getmPressure() {
		return mPressure;
	}

	public float getmHumidity() {
		return mHumidity;
	}
	
}
